package upcweb.util;

import java.sql.SQLException;
import java.util.ArrayList;

import upcweb.exception.WebDAOException;

public class ClsReturn {

	private int result;
	private boolean flag;
	private String message;
	private int rows;
	private Exception exception;
	private int errNumber;
	
	private String script;
	
	public int getErrNumber() {
		return errNumber;
	}

	public void setErrNumber(int errNumber) {
		this.errNumber = errNumber;
	}
	private ArrayList<String> values =  new ArrayList<String>();
	private ArrayList<String> inValues = new ArrayList<String>();


	public ArrayList<String> getValues() {
		return values;
	}

	public void setValues(ArrayList<String> values) {
		this.values = values;
	}

	public ArrayList<String> getInValues() {
		return inValues;
	}

	public void setInValues(ArrayList<String> inValues) {
		this.inValues = inValues;
	}

	public ClsReturn() {
		// TODO Auto-generated constructor stub
	}
	
	public void setOkMessage(String msg){
		if (isFlag()){
			script = "ShowOk('" + msg + "');";
		}
		else {
			script = "ShowError('" + getMessage() + "');";
		}
	}
	
	public String getErrScript(){
		return  "ShowError('" + getMessage() + "');";
	}
	
	public String getScript() {
		return script;
	}

	public void setScript(String script) {
		this.script = script;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public ClsReturn(Exception exception) {
		super();
		System.err.println("Error clsReturn : " + exception.getMessage());
		this.result = 0;
		this.flag = false;
		this.exception = exception;
		this.message = exception.getMessage();	
		//this.errNumber = exception.getErrorCode();
	}
	
	public ClsReturn(SQLException exception) {
		super();
		System.err.println("Error clsReturn : " + exception.getMessage());
		this.result = 0;
		this.flag = false;
		this.exception = exception;
		this.message = exception.getErrorCode() + " : " + exception.getMessage();	
		this.errNumber = exception.getErrorCode();
	}
	
	public ClsReturn(boolean flag) {
		super();
		this.flag = flag;
		//this.result = result;
		this.message = message;
		this.exception = exception;
	}
	
	public boolean isFlag() {
		return flag;
	}

	public void setFlag(boolean flag) {
		this.flag = flag;
	}

	public ClsReturn(int result) {
		super();
		this.result = result;
		this.message = message;
		this.exception = exception;
	}
	
	public int getResult() {
		return result;
	}
	public void setResult(int result) {
		this.result = result;
	}
	public String getMessage() {
		message = message.replaceAll("'", "\"");
		//System.out.println(getErrNumber());
		if (getErrNumber()==1062){
			return "Ya existe un registro con los mismos campos primarios";
		}
		else if (getErrNumber()==1452){
			return "El registro que desea agregar no cumple con la referencia necesaria";
		}
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public Exception getException() {
		return exception;
	}
	public void setException(Exception exception) {
		this.exception = exception;
	}
	
	
	
}
